<?php require_once('../Connections/hitekforyou.php'); ?>
<?php
require_once('checklogin.php');
error_reporting(0);
// Load the common classes
require_once('../includes/common/KT_common.php');

// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');

// Load the KT_back class
require_once('../includes/nxt/KT_back.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");

// Make unified connection variable
$conn_hitekforyou = new KT_connection($hitekforyou, $database_hitekforyou);



//start Trigger_CheckPasswords trigger
//remove this line if you want to edit the code by hand
function Trigger_CheckPasswords(&$tNG) {
  $myThrowError = new tNG_ThrowError($tNG);
  $myThrowError->setErrorMsg("Could not create account.");
  $myThrowError->setField("Matkhau");
  $myThrowError->setFieldErrorMsg("The two passwords do not match.");
  return $myThrowError->Execute();
}
//end Trigger_CheckPasswords trigger

// Start trigger
$formValidation = new tNG_FormValidation();
$formValidation->addField("TenNhanVien", true, "text", "", "", "", "Vui lòng điền đúng dữ liệu cần");
$formValidation->addField("Taikhoan", true, "text", "", "", "20", "Vui lòng điền đúng dữ liệu cần");
$formValidation->addField("Matkhau", true, "text", "", "", "20", "Vui lòng điền đúng dữ liệu cần");
$formValidation->addField("idLoai", true, "numeric", "", "", "", "Vui lòng điền đúng dữ liệu cần");
$tNGs->prepareValidation($formValidation);
// End trigger

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

//start Trigger_CheckOldPassword trigger
//remove this line if you want to edit the code by hand
function Trigger_CheckOldPassword(&$tNG) {
  return Trigger_UpdatePassword_CheckOldPassword($tNG);
}
//end Trigger_CheckOldPassword trigger

mysql_select_db($database_hitekforyou, $hitekforyou);
$query_Recordset1 = "SELECT TenLoai, idLoai FROM loainhanvien ORDER BY TenLoai";
$Recordset1 = mysql_query($query_Recordset1, $hitekforyou) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

// Make a logout transaction instance
$logoutTransaction = new tNG_logoutTransaction($conn_hitekforyou);
$tNGs->addTransaction($logoutTransaction);
// Register triggers
$logoutTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "GET", "KT_logout_now");
$logoutTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "login.php");
// Add columns
// End of logout transaction instance

// Make an insert transaction instance
$ins_nhanvien = new tNG_multipleInsert($conn_hitekforyou);
$tNGs->addTransaction($ins_nhanvien);
// Register triggers
$ins_nhanvien->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_nhanvien->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_nhanvien->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
$ins_nhanvien->registerConditionalTrigger("{POST.Matkhau} != {POST.re_Matkhau}", "BEFORE", "Trigger_CheckPasswords", 50);
// Add columns
$ins_nhanvien->setTable("nhanvien");
$ins_nhanvien->addColumn("TenNhanVien", "STRING_TYPE", "POST", "TenNhanVien");
$ins_nhanvien->addColumn("Taikhoan", "STRING_TYPE", "POST", "Taikhoan");
$ins_nhanvien->addColumn("Matkhau", "STRING_TYPE", "POST", "Matkhau");
$ins_nhanvien->addColumn("SDT", "STRING_TYPE", "POST", "SDT");
$ins_nhanvien->addColumn("DiaChi", "STRING_TYPE", "POST", "DiaChi");
$ins_nhanvien->addColumn("idLoai", "NUMERIC_TYPE", "POST", "idLoai");
$ins_nhanvien->setPrimaryKey("idNhanVien", "NUMERIC_TYPE");

// Make an update transaction instance
$upd_nhanvien = new tNG_multipleUpdate($conn_hitekforyou);
$tNGs->addTransaction($upd_nhanvien);
// Register triggers
$upd_nhanvien->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
$upd_nhanvien->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$upd_nhanvien->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
$upd_nhanvien->registerConditionalTrigger("{POST.Matkhau} != {POST.re_Matkhau}", "BEFORE", "Trigger_CheckPasswords", 50);
$upd_nhanvien->registerTrigger("BEFORE", "Trigger_CheckOldPassword", 60);
// Add columns
$upd_nhanvien->setTable("nhanvien");
$upd_nhanvien->addColumn("TenNhanVien", "STRING_TYPE", "POST", "TenNhanVien");
$upd_nhanvien->addColumn("Taikhoan", "STRING_TYPE", "POST", "Taikhoan");
$upd_nhanvien->addColumn("Matkhau", "STRING_TYPE", "POST", "Matkhau");
$upd_nhanvien->addColumn("SDT", "STRING_TYPE", "POST", "SDT");
$upd_nhanvien->addColumn("DiaChi", "STRING_TYPE", "POST", "DiaChi");
$upd_nhanvien->addColumn("idLoai", "NUMERIC_TYPE", "POST", "idLoai");
$upd_nhanvien->setPrimaryKey("idNhanVien", "NUMERIC_TYPE", "GET", "idNhanVien");

// Make an instance of the transaction object
$del_nhanvien = new tNG_multipleDelete($conn_hitekforyou);
$tNGs->addTransaction($del_nhanvien);
// Register triggers
$del_nhanvien->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Delete1");
$del_nhanvien->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
// Add columns
$del_nhanvien->setTable("nhanvien");
$del_nhanvien->setPrimaryKey("idNhanVien", "NUMERIC_TYPE", "GET", "idNhanVien");

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rscustom = $tNGs->getRecordset("custom");
$row_rscustom = mysql_fetch_assoc($rscustom);
$totalRows_rscustom = mysql_num_rows($rscustom);

// Get the transaction recordset
$rsnhanvien = $tNGs->getRecordset("nhanvien");
$row_rsnhanvien = mysql_fetch_assoc($rsnhanvien);
$totalRows_rsnhanvien = mysql_num_rows($rsnhanvien);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="quantri.css" rel="stylesheet" type="text/css" />
<script src="../AC_RunActiveContent.js" type="text/javascript"></script>

<title>Quản trị web HitekForYou</title>
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script src="../includes/skins/style.js" type="text/javascript"></script><?php echo $tNGs->displayValidationRules();?><script src="../includes/nxt/scripts/form.js" type="text/javascript"></script><script src="../includes/nxt/scripts/form.js.php" type="text/javascript"></script><script type="text/javascript">
$NXT_FORM_SETTINGS = {
  duplicate_buttons: true,
  show_as_grid: true,
  merge_down_value: true
}
</script>
</head>

<body>

<?php include("admin_template/header.php"); ?>
<?php include("admin_template/admin_banner.php"); ?> 
<table id="main" width="990" border="1" align="center" cellpadding="0" cellspacing="0">
 <tr>
    <td width="200" align="left" valign="top" bgcolor="#66CC00" id="cottrai">
      <div align="left">
      <?php include("menu.php"); ?>  
      </div>       </td>
    <td id="cotphai" width="790" align="left" valign="top" bgcolor="#CCFF00">
     
  
   
<div class="KT_tng">
  <h1>
    <?php 
// Show IF Conditional region1 
if (@$_GET['idNhanVien'] == "") {
?>
Thêm
    <?php 
// else Conditional region1
} else { ?>
    Cập nhật
    <?php } 
// endif Conditional region1
?>
    Nhân viên </h1>
  <div class="KT_tngform">
    <form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
      <?php $cnt1 = 0; ?>
      <?php do { ?>
      <?php $cnt1++; ?>
      <?php 
// Show IF Conditional region1 
if (@$totalRows_rsnhanvien > 1) {
?>
      <h2><?php echo NXT_getResource("Record_FH"); ?> <?php echo $cnt1; ?></h2>
      <?php } 
// endif Conditional region1
?>
      <table cellpadding="2" cellspacing="0" class="KT_tngtable">
        <tr>
          <td class="KT_th"><label for="TenNhanVien_<?php echo $cnt1; ?>">Tên Nhân Viên:</label></td>
          <td><input type="text" name="TenNhanVien_<?php echo $cnt1; ?>" id="TenNhanVien_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsnhanvien['TenNhanVien']); ?>" size="32" maxlength="255" />
              <?php echo $tNGs->displayFieldHint("TenNhanVien");?> <?php echo $tNGs->displayFieldError("nhanvien", "TenNhanVien", $cnt1); ?> </td>
        </tr>
        <tr>
          <td class="KT_th"><label for="Taikhoan_<?php echo $cnt1; ?>">Tài khoản:</label></td>
          <td><input type="text" name="Taikhoan_<?php echo $cnt1; ?>" id="Taikhoan_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsnhanvien['Taikhoan']); ?>" size="32" maxlength="20" />
              <?php echo $tNGs->displayFieldHint("Taikhoan");?> <?php echo $tNGs->displayFieldError("nhanvien", "Taikhoan", $cnt1); ?> </td>
        </tr>
        <?php 
// Show IF Conditional show_old_Matkhau_on_update_only 
if (@$_GET['idNhanVien'] != "") {
?>
        <tr>
          <td class="KT_th"><label for="old_Matkhau_<?php echo $cnt1; ?>">Mật khẩu cũ:</label></td>
          <td><input type="password" name="old_Matkhau_<?php echo $cnt1; ?>" id="old_Matkhau_<?php echo $cnt1; ?>" value="" size="32" maxlength="20" />
              <?php echo $tNGs->displayFieldError("nhanvien", "old_Matkhau", $cnt1); ?> </td>
        </tr>
        <?php } 
// endif Conditional show_old_Matkhau_on_update_only
?>
        <tr>
          <td class="KT_th"><label for="Matkhau_<?php echo $cnt1; ?>">Mật khẩu:</label></td>
          <td><input type="password" name="Matkhau_<?php echo $cnt1; ?>" id="Matkhau_<?php echo $cnt1; ?>" value="" size="32" maxlength="20" />
              <?php echo $tNGs->displayFieldHint("Matkhau");?> <?php echo $tNGs->displayFieldError("nhanvien", "Matkhau", $cnt1); ?> </td>
        </tr>
        <tr>
          <td class="KT_th"><label for="re_Matkhau_<?php echo $cnt1; ?>">Nhập lại Mật khẩu:</label></td>
          <td><input type="password" name="re_Matkhau_<?php echo $cnt1; ?>" id="re_Matkhau_<?php echo $cnt1; ?>" value="" size="32" maxlength="20" />
          </td>
        </tr>
        <tr>
          <td class="KT_th"><label for="SDT_<?php echo $cnt1; ?>">Số điện thoại:</label></td>
          <td><input type="text" name="SDT_<?php echo $cnt1; ?>" id="SDT_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsnhanvien['SDT']); ?>" size="32" maxlength="20" />
              <?php echo $tNGs->displayFieldHint("SDT");?> <?php echo $tNGs->displayFieldError("nhanvien", "SDT", $cnt1); ?> </td>
        </tr>
        <tr>
          <td class="KT_th"><label for="DiaChi_<?php echo $cnt1; ?>">Địa chỉ:</label></td>
          <td><input type="text" name="DiaChi_<?php echo $cnt1; ?>" id="DiaChi_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsnhanvien['DiaChi']); ?>" size="32" maxlength="255" />
              <?php echo $tNGs->displayFieldHint("DiaChi");?> <?php echo $tNGs->displayFieldError("nhanvien", "DiaChi", $cnt1); ?> </td>
        </tr>
        <tr>
          <td class="KT_th"><label for="idLoai_<?php echo $cnt1; ?>">Loại nhân viên :</label></td>
          <td><select name="idLoai_<?php echo $cnt1; ?>" id="idLoai_<?php echo $cnt1; ?>">

            <?php 
do {  
?>
            <option value="<?php echo $row_Recordset1['idLoai']?>"<?php if (!(strcmp($row_Recordset1['idLoai'], $row_rsnhanvien['idLoai']))) {echo "SELECTED";} ?>><?php echo $row_Recordset1['TenLoai']?></option>
            <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  $rows = mysql_num_rows($Recordset1);
  if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  }
?>
          </select>
              <?php echo $tNGs->displayFieldError("nhanvien", "idLoai", $cnt1); ?> </td>
        </tr>
      </table>
      <input type="hidden" name="kt_pk_nhanvien_<?php echo $cnt1; ?>" class="id_field" value="<?php echo KT_escapeAttribute($row_rsnhanvien['kt_pk_nhanvien']); ?>" />
      <?php } while ($row_rsnhanvien = mysql_fetch_assoc($rsnhanvien)); ?>
      <div class="KT_bottombuttons">
        <div>
          <?php 
      // Show IF Conditional region1
      if (@$_GET['idNhanVien'] == "") {
      ?>
          <input type="submit" name="KT_Insert1" id="KT_Insert1" value="Thêm" />
          <?php 
      // else Conditional region1
      } else { ?>
          <div class="KT_operations">
            <input type="submit" name="KT_Insert1" value="Thêm" onclick="nxt_form_insertasnew(this, 'idNhanVien')" />
          </div>
          <input type="submit" name="KT_Update1" value="Cập nhật" />
          <input type="submit" name="KT_Delete1" value="Xóa" onclick="return confirm('<?php echo NXT_getResource("Bạn có chắc muốn xóa ?"); ?>');" />
          <?php }
      // endif Conditional region1
      ?>
          <input type="button" name="KT_Cancel1" value="Hủy" onclick="return UNI_navigateCancel(event, '../includes/nxt/back.php')" />
        </div>
      </div>
    </form>
  </div>
  <br class="clearfixplain" />
</div>
<p>&nbsp;</p>
</tr>
</table><?php include("admin_template/footer.php"); ?>  

</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

